package com.yanqu.road.server.gameplayer.module.activity;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.dafuweng.DFWConfig;
import com.yanqu.road.entity.activity.hanghai.config.HangHaiConfig;
import com.yanqu.road.entity.activity.mall.MallActivityInfo;
import com.yanqu.road.entity.activity.oldplayerreturn.OldPlayerReturnShopLimit;
import com.yanqu.road.entity.activity.ppl.PplUserData;
import com.yanqu.road.entity.bag.UseCommonGoodsResult;
import com.yanqu.road.entity.bag.UseGoodsResult;
import com.yanqu.road.entity.config.goods.BuyGoodsResult;
import com.yanqu.road.entity.config.goods.GoodsInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.config.goods.OpenGoodsBagResult;
import com.yanqu.road.entity.enums.*;
import com.yanqu.road.entity.enums.activity.eActivityChargeType;
import com.yanqu.road.entity.log.LogActivityIceServerGift;
import com.yanqu.road.entity.log.LogActivityStarLight;
import com.yanqu.road.entity.log.LogBuy;
import com.yanqu.road.entity.player.UserActivityScore;
import com.yanqu.road.entity.player.UserMallBuyCount;
import com.yanqu.road.entity.player.UserPageantData;
import com.yanqu.road.entity.task.args.XiaoyuCostumeActivityArgs;
import com.yanqu.road.entity.tradewar.UserTradeWarInfo;
import com.yanqu.road.logic.bussiness.player.UserActivityBussiness;
import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.logic.helper.ActivityHelper;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.game2048.PageantModule;
import com.yanqu.road.server.gameplayer.module.activity.iceservergift.IceServerGiftModule;
import com.yanqu.road.server.gameplayer.module.activity.oldplayerreturn.OldPlayerReturnModule;
import com.yanqu.road.server.gameplayer.module.activity.ppl.PplModule;
import com.yanqu.road.server.gameplayer.module.activity.starlight.StarLightModule;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.gameplayer.module.player.BagModule;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.gameplayer.module.player.TradeWarModule;
import com.yanqu.road.server.gameplayer.module.recharge.RechargeGainModule;
import com.yanqu.road.server.manger.activity.*;
import com.yanqu.road.server.manger.activity.bowart.BowArtMgr;
import com.yanqu.road.server.manger.activity.businessreunion.BusinessReunionActivityMgr;
import com.yanqu.road.server.manger.activity.busyfarming.BusyFarmingMgr;
import com.yanqu.road.server.manger.activity.cat.CatMgr;
import com.yanqu.road.server.manger.activity.carptrip.CarpTripMgr;
import com.yanqu.road.server.manger.activity.celebration.CelebrationMgr;
import com.yanqu.road.server.manger.activity.climbtower.ClimbTowerMgr;
import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.server.manger.activity.dragonboatrace.DragonBoatRaceMgr;
import com.yanqu.road.server.manger.activity.drink.DrinkMgr;
import com.yanqu.road.server.manger.activity.fanxiuspring.FanXiuSpringMgr;
import com.yanqu.road.server.manger.activity.fellingtrees.FellingTreesMgr;
import com.yanqu.road.server.manger.activity.ghost.GhostMgr;
import com.yanqu.road.server.manger.activity.gourdchild.GourdChildMgr;
import com.yanqu.road.server.manger.activity.gourdplant.GourdPlantMgr;
import com.yanqu.road.server.manger.activity.greattrade.GreatTradeMgr;
import com.yanqu.road.server.manger.activity.hanghai.HangHaiMgr;
import com.yanqu.road.server.manger.activity.hell.HellMgr;
import com.yanqu.road.server.manger.activity.huashigang.HuaShiGangMgr;
import com.yanqu.road.server.manger.activity.jianchuanghua.JianChuangHuaMgr;
import com.yanqu.road.server.manger.activity.lanruosi.LanRuoSiMgr;
import com.yanqu.road.server.manger.activity.oldplayerreturn.OldPlayerReturnMgr;
import com.yanqu.road.server.manger.activity.operamask.OperaMaskMgr;
import com.yanqu.road.server.manger.activity.orewar.OreWarActivityMgr;
import com.yanqu.road.server.manger.activity.pawnshop.PawnshopMgr;
import com.yanqu.road.server.manger.activity.ppl.PplMgr;
import com.yanqu.road.server.manger.activity.rankunionwar.RankUnionWarMgr;
import com.yanqu.road.server.manger.activity.seacraft.SeacraftPirateRiotMgr;
import com.yanqu.road.server.manger.activity.shrek.DouLuoShrekMgr;
import com.yanqu.road.server.manger.activity.shuihu.ShuiHuMgr;
import com.yanqu.road.server.manger.activity.shuihuyezicard.ShuiHuYeZiCardMgr;
import com.yanqu.road.server.manger.activity.shushan.ShuShanMgr;
import com.yanqu.road.server.manger.activity.springdinner.SpringDinnerMgr;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdActivityMgr;
import com.yanqu.road.server.manger.activity.suoyao.SuoYaoMgr;
import com.yanqu.road.server.manger.activity.tanghulu.TangHuLuMgr;
import com.yanqu.road.server.manger.activity.tonbing.TonBingMgr;
import com.yanqu.road.server.manger.activity.tonbingchannel.ChannelTonBingMgr;
import com.yanqu.road.server.manger.activity.tongbing.TongBingMgr;
import com.yanqu.road.server.manger.activity.toyhouse.ToyHouseMgr;
import com.yanqu.road.server.manger.activity.twins.TwinsMgr;
import com.yanqu.road.server.manger.activity.unionwar.UnionWarActivityMgr;
import com.yanqu.road.server.manger.activity.wanyao.WanYaoMgr;
import com.yanqu.road.server.manger.activity.washe.WasheMgr;
import com.yanqu.road.server.manger.activity.winterLove.WinterLoveMgr;
import com.yanqu.road.server.manger.activity.worldcup.WorldCupMgr;
import com.yanqu.road.server.manger.activity.xiaowuRecall.XiaowuRecallMgr;
import com.yanqu.road.server.manger.activity.xiayue.XiaYueMgr;
import com.yanqu.road.server.manger.activity.yearMaster.YearMasterMgr;
import com.yanqu.road.server.manger.activity.yingxin.YingXinMgr;
import com.yanqu.road.server.manger.config.GoodsBagMgr;
import com.yanqu.road.server.manger.config.MallMgr;
import com.yanqu.road.server.manger.config.MallRechargeConfigMgr;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.server.manger.maidian.entity.BuyShopItem;
import com.yanqu.road.server.manger.maidian.resource.BuyItemLog;
import com.yanqu.road.server.manger.player.WorldMessageMgr;
import com.yanqu.road.server.manger.recharge.RechargeMgr;
import com.yanqu.road.server.pb.MallPb;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.LocalDateTimeHelper;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class ActivityMallModule extends GeneralModule {

    private Map<Integer, UserMallBuyCount> userMallBuyCountMap;

    //activityI - goodsId
    private Map<Integer, Map<Integer, UserActivityScore>> userActivityScoreMap = new ConcurrentHashMap<>();

    public ActivityMallModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean afterLoadData() {
        return false;
    }

    @Override
    public boolean saveData() {
        if(null != userMallBuyCountMap) {
            for (UserMallBuyCount buyCount : userMallBuyCountMap.values()) {
                if (buyCount.isInsertOption()) {
                    UserActivityBussiness.addUserMallBuyCount(buyCount);
                } else if (buyCount.isUpdateOption()) {
                    UserActivityBussiness.updateUserMallBuyCount(buyCount);
                }
            }
        }

        if (userActivityScoreMap != null) {
            for (Map<Integer, UserActivityScore> scoreMap : userActivityScoreMap.values()) {
                for (UserActivityScore score : scoreMap.values()) {
                    if (score.isInsertOption()) {
                        UserActivityBussiness.addUserActivityScore(score);
                    } else if (score.isUpdateOption()) {
                        UserActivityBussiness.updateUserActivityScore(score);
                    }
                }
            }
        }
        return true;
    }

    @Override
    public boolean loadData() {
        userMallBuyCountMap = UserActivityBussiness.getUserMallBuyCountMap(player.getUserId());
        userActivityScoreMap = UserActivityBussiness.getUserActivityScoreMap(player.getUserId());
        return true;
    }

    @Override
    public void loginSendMsg() {
        syncMallBuyCount();
        syncActivityScore();
    }

    public void syncActivityScore() {
        if (userActivityScoreMap != null) {
            List<UserActivityScore> syncList = new ArrayList<>();
            for (Map<Integer, UserActivityScore> scoreMap : userActivityScoreMap.values()) {
                syncList.addAll(new ArrayList<>(scoreMap.values()));
            }
            syncActivityScore(syncList);
        }
    }

    public void syncSpecialActivityScore(List<UserActivityScore> userActivityScores) {
        //商战
        UserTradeWarInfo userTradeWarInfo = player.getModule(TradeWarModule.class).getUserTradeWarInfo();
        if (userTradeWarInfo != null) {
            syncOldConfigScore(userTradeWarInfo.getActivityId(), GameConfig.GAME_MONEY_CROSS_TRADE_WAR_SCORE, userTradeWarInfo.getCrossTradeWarMoney(), userActivityScores);
        }
        //选美大赛
        List<ActivityInfo> openActivityInfoList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.PageantActivity.getValue());
        for (ActivityInfo activityInfo : openActivityInfoList) {
            UserPageantData userPageantData = player.getModule(PageantModule.class).getUserPageantData(activityInfo.getActivityId());
            if (userPageantData != null) {
                syncOldConfigScore(userPageantData.getActivityId(), eItemId.XUAN_MEI_JI_FEN.getValue(), userPageantData.getTodayGetMoney(), userActivityScores);
            }
        }
        //平乐坊
        PplUserData userData = player.getModule(PplModule.class).getUserData();
        if (userData != null) {
            syncOldConfigScore(userData.getActivityId(), eItemId.PING_LE_FANG_JI_FEN.getValue(), userData.getTodayScore(), userActivityScores);
        }
    }

    public void syncOldConfigScore(int activityId, int goodsId, long score, List<UserActivityScore> userActivityScores) {
        if (!userActivityScoreMap.containsKey(activityId)) {
            addScore(activityId, goodsId, 0);
        }
        for (UserActivityScore userActivityScore : userActivityScores) {
            if (activityId == userActivityScore.getActivityId()) {
                if (userActivityScore.getDayScore() < score) {
                    userActivityScore.setDayScore(score);
                }
                if (userActivityScore.getTotalScore() < score) {
                    userActivityScore.setTotalScore(score);
                }
            }
        }
    }

    public void syncMallBuyCount(){
        if(null != userMallBuyCountMap) {
            syncMallBuyCount(new ArrayList<>(userMallBuyCountMap.values()));
        }
    }

    /**
     * 每日重置
     */
    public void resetOneDay() {
        if(!hasActivity()){
            return;
        }
        long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp() / 1000;
        List<UserMallBuyCount> syncList = new ArrayList<>();
        if(null != userMallBuyCountMap){
            for (UserMallBuyCount userMallBuyCount : userMallBuyCountMap.values()) {
                MallInfo mallInfo = MallMgr.getMallInfoByMallId(userMallBuyCount.getMallId());
                if(null == mallInfo){
                    continue;
                }
                boolean isReset = MallMgr.isMallBuyCountReset(zeroTime, userMallBuyCount, mallInfo);
                if(isReset) {
                    userMallBuyCount.setCount(0);
                    userMallBuyCount.setLastUpdateTime(zeroTime);
                    syncList.add(userMallBuyCount);
                }
            }
            syncMallBuyCount(syncList);
        }
    }

    //自定义时间重置
    public void resetCustomMall(int shopType,long resetTime) {
        if(!hasActivity()){
            return;
        }
        List<UserMallBuyCount> syncList = new ArrayList<>();
        for (UserMallBuyCount userMallBuyCount : userMallBuyCountMap.values()) {
            MallInfo mallInfo = MallMgr.getMallInfoByMallId(userMallBuyCount.getMallId());
            if (null == mallInfo) {
                continue;
            }
            if (mallInfo.getShopType() == shopType && resetTime > userMallBuyCount.getLastUpdateTime()) {
                if (mallInfo.getLimitBuyType() == eLimitBuyType.Custom.getValue()) {
                    userMallBuyCount.setCount(0);
                    userMallBuyCount.setLastUpdateTime(resetTime);
                    syncList.add(userMallBuyCount);
                }
            }
        }
        syncMallBuyCount(syncList);
    }

    /**
     * 有带商品的活动存在 v6.0.0修改,大多数活动都有兑换商店同步,此处不需要一个个加活动判断否则容易忘加
     */
    private boolean hasActivity(){
//        List<ActivityInfo> commonActivityList = CommonActivityMgr.getAllOpenCommonActivityInfoList();
//        ActivityInfo tradeWarActivity = TradeWarActivityMgr.getOpenActivityInfo();
//        List<ActivityInfo> crossRankActivityList = NormalActivityMgr.getCrossRankActivityInfoList();
//        List<ActivityInfo> oreWarActivityList = OreWarActivityMgr.getOpenActivityInfoList();
//        List<ActivityInfo> mysteriousMerchantActivityList = NormalActivityMgr.getMysteriousMerchantActivityInfoList();
//        List<ActivityInfo> holidayActivityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.CrossHolidayActivity.getValue());
//        List<ActivityInfo> unionWarActivityList = UnionWarActivityMgr.getOpenActivityInfo();
//        List<ActivityInfo> treasureActivityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.TreasureActivity.getValue());
//        List<ActivityInfo> drawPicturesActivityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.DrawPicturesActivity.getValue());
//        List<ActivityInfo> cookBoyActivityList = RelationActivityMgr.getOpenActivityInfoList(eActivityType.CookingBoyActivity.getValue());
//        List<ActivityInfo> goldTokenActivityList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.RechargeActivity.getValue(),
//                eActivityChargeType.GoldTokenCharge.getChildType());
//        if(null != tradeWarActivity || commonActivityList.size() > 0 || crossRankActivityList.size() > 0 || oreWarActivityList.size() > 0 ||
//            mysteriousMerchantActivityList.size() > 0 || holidayActivityList.size() > 0 || treasureActivityList.size() > 0
//                || drawPicturesActivityList.size() > 0 || unionWarActivityList.size() > 0 || cookBoyActivityList.size() > 0
//                || goldTokenActivityList.size() > 0
//        ) {
//            return true;
//        }
//
//        if (ActivityMgr.activityInShowTime(HuaShiGangMgr.getActivityInfo())) {
//            return true;
//        }
//
//        if (ActivityMgr.activityInShowTime(GamePageantMgr.getActivityInfo())) {
//            return true;
//        }
//
//        if (PplMgr.isActivityInShowTime()) {
//            return true;
//        }
//
//        if (ActivityMgr.activityInShowTime(YearMasterMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(JianChuangHuaMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(TangHuLuMgr.getActivityInfo())) {
//            return true;
//        }
//        DFWConfig dfwConfig = DaFuWengMgr.getDfwConfig();
//        if (dfwConfig != null && ActivityMgr.activityInShowTime(dfwConfig.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(GhostMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(ShuiHuMgr.getActivityInfo())) {
//            return true;
//        }
//        HangHaiConfig hangHaiConfig = HangHaiMgr.getHangHaiConfig();
//        if (hangHaiConfig != null && ActivityMgr.activityInShowTime(hangHaiConfig.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(BowArtMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(SuoYaoMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(BusyFarmingMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(DragonBoatRaceMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(CelebrationMgr.getActivityInfo())){
//            return true;
//        }
//        if(PawnshopMgr.isActivityInShowTime()){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(DrinkMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(XiaYueMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(LanRuoSiMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(GourdChildMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(GourdPlantMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(WinterLoveMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(YingXinMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(HellMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(DouLuoDaLuMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(XiaowuRecallMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(DouLuoShrekMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(ShuiHuYeZiCardMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(SpringDinnerMgr.getActivityInfo())){
//            return true;
//        }
//        if(NormalActivityMgr.getOpenActivityInfoList(eActivityType.ChannelRankActivity.getValue()).size() > 0){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(ToyHouseMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(SeacraftPirateRiotMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(ShuShanMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(BusinessReunionActivityMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(TongBingMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(ClimbTowerMgr.getActivityInfo())) {
//            return true;
//        }
//        if (OperaMaskMgr.getConfig() != null && ActivityMgr.activityInShowTime(OperaMaskMgr.getConfig().getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(GreatTradeMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(RankUnionWarMgr.getActivity())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(FellingTreesMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(TwinsMgr.getActivity())) {
//            return true;
//        }
//        if (WasheMgr.getWasheConfig() != null && ActivityMgr.activityInShowTime(WasheMgr.getWasheConfig().getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(CatMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(WorldCupMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(CarpTripMgr.getActivityInfo())) {
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(FanXiuSpringMgr.getActivityInfo(FanXiuSpringMgr.CHILD_TYPE_OTHER))){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(TonBingMgr.getActivityInfo())){
//            return true;
//        }
//        if (ActivityMgr.activityInShowTime(ChannelTonBingMgr.getActivityInfo())){
//            return true;
//        }
        return true;
    }

    /**
     * 购买逻辑
     */
    public BuyGoodsResult buyGoods(MallInfo mallInfo, int count) {
        BuyGoodsResult result = new BuyGoodsResult();
        if (isOldReturnSpecialMall(mallInfo)) {               //老玩家回归特殊商店走特殊限购 想改通用的特殊判断
            if (isSpecialLimitBuy(mallInfo, count)) {
                result.setRet(GameErrorCode.E_MALL_LIMIT_BUY);
                return result;
            }
        } else {
            if (isLimitBuy(mallInfo, count) || isScoreLimitBuy(mallInfo, count)) {
                result.setRet(GameErrorCode.E_MALL_LIMIT_BUY);
                return result;
            }
        }

        if (mallInfo.getRechargeId() > 0) {
            result.setRet(GameErrorCode.E_MALL_LIMIT_BUY);
            return result;
        }

        CurrencyModule currencyModule = player.getModule(CurrencyModule.class);
        //消耗
        Property consume = MallMgr.getPriceConsume(count, getMallBuyCount(mallInfo.getMallId()), mallInfo);
        eLogMoneyType sonLog = eLogMoneyType.MallBuy;
        if(mallInfo.getShopType() == eShopType.CommonActivityBuyMall.getValue() || mallInfo.getShopType() == eShopType.CommonActivityExchangeMall.getValue()){
            sonLog = eLogMoneyType.CommonActivityMallBuy;
        }else if(mallInfo.getShopType() == eShopType.CrossTradeWarActivityMall.getValue()){
            sonLog = eLogMoneyType.CrossTradeWarMallBuy;
        }else if(mallInfo.getShopType() == eShopType.CrossRankActivityIngotMall.getValue()){
            sonLog = eLogMoneyType.CrossRankActivityMallBuy;
        }else if(mallInfo.getShopType() == eShopType.OreWarActivityMall.getValue()){
            sonLog = eLogMoneyType.OreWarMallBuy;
        }else if(mallInfo.getShopType() == eShopType.MysteriousMerchantMall.getValue()){
            sonLog = eLogMoneyType.MysteriousMerchantMallBuy;
        }else if(mallInfo.getShopType() == eShopType.CrossHolidayActivityMall.getValue()){
            sonLog = eLogMoneyType.HolidayActivityMallBuy;
        }else if (mallInfo.getShopType() == eShopType.HuaShiGangExchangeMall.getValue()) {
            sonLog = eLogMoneyType.HuaShiGangExchange;
        }else if (mallInfo.getShopType() == eShopType.PageantActivityMall.getValue()) {
            sonLog = eLogMoneyType.PageantExchangeShop;
        }else if (mallInfo.getShopType() == eShopType.ThrowingPotMall.getValue()){
            sonLog = eLogMoneyType.ThrowingPotShop;
        }else if(mallInfo.getShopType() == eShopType.PatronsSkinCombMall1.getValue() || mallInfo.getShopType() == eShopType.PatronsSkinCombMall2.getValue()){
            //门客皮肤组合
            sonLog = eLogMoneyType.PatronsSkinCombActivityMallBuy;
        }else if (mallInfo.getShopType() == eShopType.YearMasterMall.getValue()){
            sonLog = eLogMoneyType.YearMasterShop;
        }else if (mallInfo.getShopType() == eShopType.TreasureMall.getValue()) {
            sonLog = eLogMoneyType.TreasureShop;
        }else if (mallInfo.getShopType() == eShopType.PplMall.getValue()) {
            sonLog = eLogMoneyType.PplExchangeShop;
        }else if (mallInfo.getShopType() == eShopType.JianChuangHuaMall.getValue()) {
            sonLog = eLogMoneyType.JianChuangHuaExchangeShop;
        }else if(mallInfo.getShopType() == eShopType.DaFuWengMall.getValue()){
            sonLog = eLogMoneyType.DaFuWengExchangeMall;
        } else if (mallInfo.getShopType() == eShopType.DrawPicturesMall.getValue()) {
            sonLog = eLogMoneyType.DrawPictureExchangeShop;
        }else if(mallInfo.getShopType() == eShopType.UnionWarActivityMall.getValue() || mallInfo.getShopType() == eShopType.UnionWarActivityIngotMall.getValue()){
            sonLog = eLogMoneyType.UnionWarActivityExchangeShop;
        }else if(mallInfo.getShopType() == eShopType.ShuiHuMall.getValue()) {
            sonLog = eLogMoneyType.ShuiHuActivityExchangeMall;
        }else if(mallInfo.getShopType() == eShopType.BowArtActivityMall.getValue() || mallInfo.getShopType() == eShopType.BowArtActivityBuyMall.getValue()) {
            sonLog = eLogMoneyType.BowArtActivityExchangeMall;
        }else if(mallInfo.getShopType() == eShopType.PawnshopMall.getValue()){
            sonLog = eLogMoneyType.PawnshopMallBuy;
        }else if(mallInfo.getShopType() == eShopType.BusyFarmingMall.getValue()){
            sonLog = eLogMoneyType.BusyFarmingActivityExchangeMall;
        } else if (mallInfo.getShopType() == eShopType.HuaShiGangBattleExchangeMall.getValue()) {
            sonLog = eLogMoneyType.HuaShiGangBattleExchange;
        } else if (mallInfo.getShopType() == eShopType.DragonBoatRaceActivityMall.getValue()) {
            sonLog = eLogMoneyType.DragonBoatRaceActivityExchangeMall;
        } else if (mallInfo.getShopType() == eShopType.SuoYaoMall.getValue()) {
            sonLog = eLogMoneyType.SuoYaoActivityMallBuy;
        } else if (mallInfo.getShopType() == eShopType.GhostMall.getValue()) {
            sonLog = eLogMoneyType.GhostExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.DrinkActivityMall.getValue()) {
            sonLog = eLogMoneyType.DrinkExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.XiaYueMall.getValue()) {
            sonLog = eLogMoneyType.XiaYueExchangeMall;
        }else if(mallInfo.getShopType() == eShopType.DunHuangShiKuMall.getValue()){
            sonLog = eLogMoneyType.DunHuangShiKuExchangeMall;
        }else if(mallInfo.getShopType() == eShopType.CookBoy1ActivityMall.getValue()){
            sonLog = eLogMoneyType.CrossCookBoyActivityBuyMall1;
        }else if(mallInfo.getShopType() == eShopType.CookBoy2ActivityMall.getValue()){
            sonLog = eLogMoneyType.CrossCookBoyActivityBuyMall2;
        }else if(mallInfo.getShopType() == eShopType.ChefDuelPhase2ScoreShop.getValue()){
            sonLog = eLogMoneyType.CrossChefDuelActivityBuyMall2;
        }else if(mallInfo.getShopType() == eShopType.CookBoy3ActivityMall.getValue()){
            sonLog = eLogMoneyType.CrossCookBoyActivityBuyMall3;
        }else if(mallInfo.getShopType() == eShopType.ChefDuelPhase3ScoreMall.getValue()){
            sonLog = eLogMoneyType.CrossChefDuelActivityBuyMall3;
        }else if(mallInfo.getShopType() == eShopType.CelebrationActivityMall.getValue() || mallInfo.getShopType() == eShopType.CelebrationActivityBuyMall.getValue()){
            sonLog = eLogMoneyType.CelebrationExchangeMall;
        }else if (mallInfo.getShopType() == eShopType.LanRuoSiActivityMall.getValue()) {
            sonLog = eLogMoneyType.LanRuoSiExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.GuiChuiDengActivityMall.getValue()) {
            sonLog = eLogMoneyType.GuiChuiDengMallBuy;
        }else if (mallInfo.getShopType() == eShopType.GourdChildActivityMall.getValue()){
            sonLog = eLogMoneyType.GourdChildMallBuy;
        }else if (mallInfo.getShopType() == eShopType.GourdPlantActivityMall.getValue()){
            sonLog = eLogMoneyType.GourdPlantMallBuy;
        }else if (mallInfo.getShopType() == eShopType.WinterLoveActivityMall.getValue()){
            sonLog = eLogMoneyType.WinterLoveMallBuy;
        } else if (mallInfo.getShopType() == eShopType.YingXinActivityMall.getValue()) {
            sonLog = eLogMoneyType.YingXinActivityShopBuy;
        }else if (mallInfo.getShopType() == eShopType.HellActivityMall.getValue()){
            sonLog = eLogMoneyType.HellActivityMallBuy;
        }else if (mallInfo.getShopType() == eShopType.XiaowuRecallActivityMall.getValue()){
            sonLog = eLogMoneyType.XiaowuRecallMallBuy;
        }else if (mallInfo.getShopType() == eShopType.ShrekActivityMall.getValue()){
            sonLog = eLogMoneyType.ShrekActivityMallBuy;
        }else if (mallInfo.getShopType() == eShopType.ShrekActivityMall2.getValue()){
            sonLog = eLogMoneyType.ShrekActivityMallBuy2;
        } else if (mallInfo.getShopType() == eShopType.XiaoyuCostumeActivityMall.getValue()) {
            sonLog = eLogMoneyType.XiaoyuCostumeActivityExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.ChannelRankActivityIngotMall.getValue()) {
            sonLog = eLogMoneyType.ChannelRankActivityIngotMallBuy;
        } else if (mallInfo.getShopType() == eShopType.ChannelRankActivityExchangeMall.getValue()) {
            sonLog = eLogMoneyType.ChannelRankActivityExchangeMallBuy;
        }else if (mallInfo.getShopType() == eShopType.ShuiHuYeZiCardMall.getValue()) {
            sonLog = eLogMoneyType.ShuiHuYeZiCardMallBuy;
        }else if (mallInfo.getShopType() == eShopType.SpringDinnerActivityMall.getValue()){
            sonLog = eLogMoneyType.SpringDinnerActivityBuy;
        }else if (mallInfo.getShopType() == eShopType.SeacraftActivityMall.getValue()){
            sonLog = eLogMoneyType.SeacraftActivityMallBuy;
        } else if (mallInfo.getShopType() == eShopType.ToyHouseExchangeMall.getValue()) {
            sonLog = eLogMoneyType.ToyHouseExchangeMallBuy;
        } else if(mallInfo.getShopType() == eShopType.ShuShanActivityMall.getValue()){
            sonLog = eLogMoneyType.ShuShanExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.TongBingFoodMall.getValue()) {
            sonLog = eLogMoneyType.TongBingFoodMall;
        } else if (mallInfo.getShopType() == eShopType.ChuHanFoodMall.getValue()) {
            sonLog = eLogMoneyType.ChuHanFoodMall;
        } else if (mallInfo.getShopType() == eShopType.TonBingFoodMall.getValue()) {
            sonLog = eLogMoneyType.TonBingFoodMall;
        } else if (mallInfo.getShopType() == eShopType.HarpsMall.getValue()) {
            sonLog = eLogMoneyType.HarpsMall;
        }  else if (mallInfo.getShopType() == eShopType.SuiTangJunZiMall.getValue()) {
            sonLog = eLogMoneyType.SuiTangFoodMall;
        } else if (mallInfo.getShopType() == eShopType.SuiTangTeHuiYBMall.getValue()) {
            sonLog = eLogMoneyType.SuiTangTeHuiYBMall;
        } else if(mallInfo.getShopType() == eShopType.ZhouNianTurntableMall.getValue()){
            sonLog = eLogMoneyType.ZhouNianTurntableMallBuy;
        } else if (mallInfo.getShopType() == eShopType.BusinessReunionActivityMall.getValue()) {
            sonLog = eLogMoneyType.BusinessReunionExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.TongBingYuanBaoMall.getValue()) {
            sonLog = eLogMoneyType.TongBingIngotsMall;
        } else if (mallInfo.getShopType() == eShopType.ChuHanYuanBaoMall.getValue()) {
            sonLog = eLogMoneyType.ChuHanIngotsMall;
        } else if (mallInfo.getShopType() == eShopType.TonBingYuanBaoMall.getValue()) {
            sonLog = eLogMoneyType.TonBingIngotsMall;
        } else if (mallInfo.getShopType() == eShopType.OperaMaskExchangeMall.getValue()) {
            sonLog = eLogMoneyType.OperaMaskActivityMall;
        } else if (mallInfo.getShopType() == eShopType.ClimbTowerActivityMall.getValue()){
            sonLog = eLogMoneyType.ClimbTowerActivityExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.DouLuoDaLuActivityMall.getValue()){
            sonLog = eLogMoneyType.DouLuoDaLuExchangeMall;
        } else if (mallInfo.getShopType() == eShopType.RankUnionWarMall.getValue()) {
            sonLog = eLogMoneyType.RankUnionWarMallBuy;
        }else if (mallInfo.getShopType() == eShopType.RankUnionWarYuanBaoMall.getValue()) {
            sonLog = eLogMoneyType.RankUnionWarMallYuanBaoBuy;
        }else if (mallInfo.getShopType() == eShopType.RankUnionWarRmbMall.getValue()) {
            sonLog = eLogMoneyType.RankUnionWarMallRmbBuy;
        } else if (mallInfo.getShopType() == eShopType.FellingTreesExchangeMall.getValue()) {
            sonLog = eLogMoneyType.FellingTreesActivityExchangeMall;
        }else if (mallInfo.getShopType() == eShopType.TwinsExchangeMall.getValue()) {
            sonLog = eLogMoneyType.TwinsMallBuy;
        } else if (mallInfo.getShopType() == eShopType.WasheExpressionMall.getValue()) {
            sonLog = eLogMoneyType.WasheExpressionMallBuy;
        }else if (mallInfo.getShopType() == eShopType.CatActivityMall.getValue()){
            sonLog = eLogMoneyType.CatActivityMallBuy;
        }else if (mallInfo.getShopType() == eShopType.WorldCupActivityMall.getValue()) {
            sonLog = eLogMoneyType.WorldCupMallBuy;
        } else if (mallInfo.getShopType() == eShopType.CarpTripExchangeMall.getValue()) {
            sonLog = eLogMoneyType.CarpTripActivityExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.FireWork2023NormalMall.getValue()) {
            sonLog = eLogMoneyType.FireWork2023NormalMallBuy;
        } else if (mallInfo.getShopType() == eShopType.FanXiuSpringMall.getValue()){
            sonLog = eLogMoneyType.FanXiuSpringExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.XiuXianMall.getValue()) {
            sonLog = eLogMoneyType.XiuXianMallMallBuy;
        }else if (mallInfo.getShopType() == eShopType.ShanHeFeastMall.getValue()) {
            sonLog = eLogMoneyType.FeastMallMallBuy;
        } else if (mallInfo.getShopType() == eShopType.VehicleCombOldMall.getValue()) {
            sonLog = eLogMoneyType.VehicleCombOldMallBuy;
        } else if (mallInfo.getShopType() == eShopType.JieShi.getValue()) {
            sonLog = eLogMoneyType.JieShiMallMallBuy;
        } else if (mallInfo.getShopType() == eShopType.PeakSeacraftActivityMall.getValue()){
            sonLog = eLogMoneyType.PeakSeacraftActivityMallBuy;
        } else if (mallInfo.getShopType() == eShopType.PeerlessBeautyLotteryMall.getValue()){
            sonLog = eLogMoneyType.PeerlessBeautyLotteryMallBuy;
        } else if (mallInfo.getShopType() == eShopType.BianLiangActivePlayerMall.getValue()){
            sonLog = eLogMoneyType.RecallPlayerMallBuy;
        } else if (mallInfo.getShopType() == eShopType.OldPlayerReturnPlayerMall.getValue()){
            sonLog = eLogMoneyType.OldPlayerMallBuy;
        } else if (mallInfo.getShopType() == eShopType.GoddessActivityMall.getValue()){
            sonLog = eLogMoneyType.GoddessMallBuy;
        } else if (mallInfo.getShopType() == eShopType.LangYaMemorialMall.getValue()){
            sonLog = eLogMoneyType.LangYaMemorialMallBuy;
        } else if (mallInfo.getShopType() == eShopType.SilkRoadScoreMall.getValue()){
            sonLog = eLogMoneyType.SilkRoadMallBuy;
        } else if (mallInfo.getShopType() == eShopType.LangYaBangScoreMall.getValue()){
            sonLog = eLogMoneyType.LangYaBangScoreMallBuy;
        } else if (mallInfo.getShopType() == eShopType.CommonWishActivityMall.getValue()){
            sonLog = eLogMoneyType.CommonWishDrawExchangeMallBuy;
            ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(mallInfo.getActivityId());
            if(activityInfo != null && activityInfo.getChildType() != 1){
                eLogMoneyType moneyType = eLogMoneyType.forValue(eLogMoneyType.CommonWishDrawExchangeMallBuy.getValue() - 1 + activityInfo.getChildType());
                if(moneyType != null){
                    sonLog = moneyType;
                }
            }
        } else if (mallInfo.getShopType() == eShopType.DeepFishingActivityMall.getValue()){
            sonLog = eLogMoneyType.DeepFishingScoreMallBuy;
        } else if (mallInfo.getShopType() == eShopType.WaSheExchangeActivityMall.getValue()){
            sonLog = eLogMoneyType.WasheExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.WaSheIngotMall.getValue()){
            sonLog = eLogMoneyType.WasheIngotMallBuy;
        } else if (mallInfo.getShopType() == eShopType.WaSheDirectPurchaseRmbMall.getValue()){
            sonLog = eLogMoneyType.WaSheDirectPurchaseRmbMallBuy;
        } else if (mallInfo.getShopType() == eShopType.AdvertisementFreeNoWatchMall.getValue()){
            sonLog = eLogMoneyType.AdvertisementNoWatchFreeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.WanYaoMall.getValue()){
            sonLog = eLogMoneyType.WanYaoMallBuy;
        } else if (mallInfo.getShopType() == eShopType.QixiRmbMall.getValue()){
            sonLog = eLogMoneyType.QixiActivityRmbMallBuy;
        } else if (mallInfo.getShopType() == eShopType.QixiMall.getValue()){
            sonLog = eLogMoneyType.QixiActivityMallBuy;
        } else if (mallInfo.getShopType() == eShopType.BaiFuJuZhenTeHuiMall.getValue()){
            sonLog = eLogMoneyType.BaiFuJuZhenTeHuiMallBuy;
        } else if (mallInfo.getShopType() == eShopType.BaiFuJuZhenYuanBaoMall.getValue()){
            sonLog = eLogMoneyType.BaiFuJuZhenYuanBaoMallBuy;
        } else if (mallInfo.getShopType() == eShopType.GuaGiftsMall.getValue()){
            sonLog = eLogMoneyType.GuaGiftsActivityMallBuy;
        }  else if (mallInfo.getShopType() == eShopType.GoldAutumnMall.getValue()){
            sonLog = eLogMoneyType.GoldAutumnActivityMallBuy;
        } else if (mallInfo.getShopType() == eShopType.DigGoldMall.getValue()) {
            sonLog = eLogMoneyType.DigGoldMallBuy;
        } else if (mallInfo.getShopType() == eShopType.DaoMuMall.getValue()){
            sonLog = eLogMoneyType.DaoMuMallBuy;
        } else if (mallInfo.getShopType() == eShopType.JinLi.getValue()){
            sonLog = eLogMoneyType.JinLiRmbMallBuy;
        } else if (mallInfo.getShopType() == eShopType.SteleSoulGiftsRmbMall.getValue()){
            sonLog = eLogMoneyType.SteleSoulRmbMallBuy;
        } else if (mallInfo.getShopType() == eShopType.JiuZhouMall.getValue()){
            sonLog = eLogMoneyType.JiuZhouExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.JiuZhouIngotMall.getValue()){
            sonLog = eLogMoneyType.JiuZhouIngotMallBuy;
        } else if (mallInfo.getShopType() == eShopType.JiuZhouRmbMall.getValue()){
            sonLog = eLogMoneyType.JiuZhouRmbMallBuy;
        } else if (mallInfo.getShopType() == eShopType.SnowGardenMall.getValue() || mallInfo.getShopType() == eShopType.SnowGardenSecondMall.getValue()){
            sonLog = eLogMoneyType.SnowGardenMallBuy;
        } else if(mallInfo.getShopType() == eShopType.SnowGardenGiftMall.getValue() || mallInfo.getShopType() == eShopType.SnowGardenSecondGiftMall.getValue()){
            sonLog = eLogMoneyType.SnowGardenGiftMallBuy;
        } else if(mallInfo.getShopType() == eShopType.SnowGardenServerBuyMall.getValue() || mallInfo.getShopType() == eShopType.SnowGardenServerSecondBuyMall.getValue()){
            sonLog = eLogMoneyType.SnowGardenServerMallBuy;
        } else if (mallInfo.getShopType() == eShopType.RuiShouMall.getValue()){
            sonLog = eLogMoneyType.RuiShouMallGet;
        } else if (mallInfo.getShopType() == eShopType.SpringDrawMall.getValue()){
            sonLog = eLogMoneyType.SpringDrawMallExchange;
        } else if (mallInfo.getShopType() == eShopType.BusinessDepartGiftMall.getValue()){
            sonLog = eLogMoneyType.BusinessDepartGiftMallBuy;
        } else if (mallInfo.getShopType() == eShopType.BusinessDepartExchangeMall.getValue()){
            sonLog = eLogMoneyType.BusinessDepartExchangeMallBuy;
        } else if (mallInfo.getShopType() == eShopType.HongXianShop.getValue()){
            sonLog = eLogMoneyType.HongXianActivityShopExchange;
        } else if (mallInfo.getShopType() == eShopType.XingYouShanShuiShop.getValue()){
            sonLog = eLogMoneyType.XingYouShanShuiShopExchange;
        } else if (mallInfo.getShopType() == eShopType.SummerGamesShop.getValue()){
            sonLog = eLogMoneyType.SummerGamesActivityShopExchange;
        } else if (mallInfo.getShopType() == eShopType.SummerQuizShop.getValue()){
            sonLog = eLogMoneyType.SummerQuizActivityShopExchange;
        } else if (mallInfo.getShopType() == eShopType.SummerGamesAllBuy.getValue()){
            sonLog = eLogMoneyType.SummerGamesServerMallBuy;
        } else if (mallInfo.getShopType() == eShopType.SonHaiGift.getValue()){
            sonLog = eLogMoneyType.SonHaiTriggerMallBuy;
        } else if (mallInfo.getShopType() == eShopType.StarLightShop.getValue()){
            sonLog = eLogMoneyType.StarLight;
            int ret = checkLinearPackLocked(mallInfo);
            if (ret != 0) {
                result.setRet(ret);
                return result;
            }
        } else if (mallInfo.getShopType() == eShopType.IceServerGiftRmbMall.getValue()){
            sonLog = eLogMoneyType.IceServerGiftRmbMall;
            int ret = checkLinearPackLocked(mallInfo);
            if (ret != 0) {
                result.setRet(ret);
                return result;
            }
        } else if (mallInfo.getShopType() == eShopType.ApprenticeIngotShop.getValue()){
            sonLog = eLogMoneyType.ApprenticeIngotShopReward;
        } else if (mallInfo.getShopType() == eShopType.ApprenticeAllBuy.getValue()){
            sonLog = eLogMoneyType.ApprenticeTgReward;
        } else if (mallInfo.getShopType() == eShopType.XingYouShanShuiRmbMall.getValue()){
            sonLog = eLogMoneyType.XingYouShanShuiMallBuy;
        } else if (mallInfo.getShopType() == eShopType.WealthScrollMall.getValue()){
            sonLog = eLogMoneyType.WealthScrollMallBuy;
        }

        if (!currencyModule.removeCurrency(consume, eLogMoneyType.Mall, sonLog, mallInfo.getMallId() + ":" + count)) {
            result.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return result;
        }

        //记录购买数量
        addMallBuyCount(mallInfo, count);

        //首充双倍
        Property resultProp = new Property();
        for(Map.Entry<Integer, BigInteger> dataEntry : mallInfo.getRewardProp().getGoods().entrySet()){
            resultProp.addProperty(dataEntry.getKey(), dataEntry.getValue().multiply(BigInteger.valueOf(count)));
        }

        if(RechargeMgr.isUseNewMultiple()) {
            player.getModule(RechargeGainModule.class).handleRechargeMultiple(mallInfo, resultProp, eRechargeGainIndex.GameFirstDouble.getValue());
        }else {
            if(player.getModule(RechargeGainModule.class).isFirstRechargeDouble(mallInfo, eRechargeGainIndex.GameFirstDouble.getValue())){//翻倍
                for(Map.Entry<Integer, BigInteger> dataEntry : resultProp.getGoods().entrySet()){
                    dataEntry.setValue(dataEntry.getValue().multiply(BigInteger.valueOf(2)));
                }
                player.getModule(RechargeGainModule.class).changeRechargeGain(mallInfo.getMallId(), eRechargeGainIndex.GameFirstDouble.getValue());
            }
        }

        //物品进口袋
        player.getModule(CurrencyModule.class).addCurrency(resultProp, eLogMoneyType.Mall, sonLog);
        result.setReward(PropertyHelper.parsePropertyToString(resultProp));
        String priceStr = MallRechargeConfigMgr.getPriceStr(mallInfo);
        AutoLogMgr.add(new LogBuy(player.getUserId(), mallInfo.getMallId(), mallInfo.getReward(), count, priceStr,
                mallInfo.getShopType(), mallInfo.getActivityType(), player.getUserInfo().getVipExp(), mallInfo.getMallMarkId()));

        BuyItemLog.trackActivityShopBuyItemSingle(player, new BuyShopItem(mallInfo, count, consume, resultProp));
        extendOperation(mallInfo);

        return result;
    }

    /**
     * 礼包购买的额外操作
     *
     * @param mallInfo mallInfo
     */
    public void extendOperation(MallInfo mallInfo) {
        if (mallInfo.getShopType() == eShopType.StarLightShop.getValue()) {
            // 记录商城补发表
            int activityId = mallInfo.getActivityId();
            ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
            int activityDay = 1; // 活动限购统一默认为第一天
            if (mallInfo.getLimitBuyType() == eLimitBuyType.DAILY.getValue()) {
                activityDay = ActivityHelper.getWhichDayAfterBeginTime(activityInfo);;
            }
            StarLightModule module = player.getModule(StarLightModule.class);
            module.modifyType(activityDay, mallInfo, 1);

            Map<Integer, List<MallInfo>> infoMap = player.getModule(StarLightModule.class).getMallInfoMapByType(activityId); // 礼包页签分类 type -> 礼包
            String[] items = mallInfo.getExtendParam().split("\\|"); // 找到购买的礼包的分类
            int type = Integer.parseInt(items[0]);
            List<MallInfo> mallInfos = infoMap.get(type);
            mallInfos.sort(Comparator.comparingInt(MallInfo::getSort));
            for (MallInfo mall : mallInfos) {
                String price = mall.getPrice();
                int cost;
                if (price.contains("=")) {
                    String[] items1 = mall.getPrice().split("=");
                    cost = Integer.parseInt(items1[1]);
                } else {
                    cost = Integer.parseInt(price);
                }
                // 直到下一个付费礼包前的所有免费礼包都加入补发表
                if (mall.getRechargeId() == 0 && cost == 0) { // 免费，没有充值ID，就算要道具，道具数量为0
                    module.addMallRecord(activityDay, mall);
                } else if (mall.getCategory() == eMallCategory.StarLight.getValue()
                        && mall.getSort() > mallInfo.getSort()) {
                    break;
                }
            }

            // 埋点日志
            LogActivityStarLight log = new LogActivityStarLight();
            log.setActivityId(mallInfo.getActivityId());
            log.setUserId(getUserId());
            String[] extendParam = mallInfo.getExtendParam().split("\\|"); // 1|0 礼包分类|类型
            log.setLightType(Integer.parseInt(extendParam[0])); // 礼包分类
            log.setNum(mallInfo.getSort());
            log.setMallId(mallInfo.getMallId());
            log.setMallMarkId(mallInfo.getMallMarkId());
            log.setLogTime(new Date());
            AutoLogMgr.add(log);
        } else if (mallInfo.getShopType() == eShopType.IceServerGiftRmbMall.getValue()) {
            // 记录商城补发表
            int activityId = mallInfo.getActivityId();
            ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
            int activityDay = 1; // 活动限购统一默认为第一天
            if (mallInfo.getLimitBuyType() == eLimitBuyType.DAILY.getValue()) {
                activityDay = ActivityHelper.getWhichDayAfterBeginTime(activityInfo);;
            }
            IceServerGiftModule module = player.getModule(IceServerGiftModule.class);
            module.modifyType(activityDay, mallInfo, 1);

            Map<Integer, List<MallInfo>> infoMap = player.getModule(IceServerGiftModule.class).getMallInfoMapByType(activityId); // 礼包页签分类 type -> 礼包
            String[] items = mallInfo.getExtendParam().split("\\|"); // 找到购买的礼包的分类
            int type = Integer.parseInt(items[0]);
            List<MallInfo> mallInfos = infoMap.get(type);
            mallInfos.sort(Comparator.comparingInt(MallInfo::getSort));
            for (MallInfo mall : mallInfos) {
                String price = mall.getPrice();
                int cost;
                if (price.contains("=")) {
                    String[] items1 = mall.getPrice().split("=");
                    cost = Integer.parseInt(items1[1]);
                } else {
                    cost = Integer.parseInt(price);
                }
                // 直到下一个付费礼包前的所有免费礼包都加入补发表
                if (mall.getRechargeId() == 0 && cost == 0) { // 免费，没有充值ID，就算要道具，道具数量为0
                    module.addMallRecord(activityDay, mall);
                } else if (mall.getCategory() == eMallCategory.IceServerGift.getValue()
                        && mall.getSort() > mallInfo.getSort()) {
                    break;
                }
            }

            // 埋点日志
            LogActivityIceServerGift log = new LogActivityIceServerGift();
            log.setActivityId(mallInfo.getActivityId());
            log.setUserId(getUserId());
            String[] extendParam = mallInfo.getExtendParam().split("\\|"); // 1|0 礼包分类|类型
            log.setLightType(Integer.parseInt(extendParam[0])); // 礼包分类
            log.setNum(mallInfo.getSort());
            log.setMallId(mallInfo.getMallId());
            log.setMallMarkId(mallInfo.getMallMarkId());
            log.setLogTime(new Date());
            AutoLogMgr.add(log);
        }
    }

    /**
     * 使用万能活动道具
     */
    public UseCommonGoodsResult useCommonActivityGoods(GoodsInfo goodsInfo, long count) {
        // 判断是否有活动
        UseCommonGoodsResult useResult = new UseCommonGoodsResult();
        List<ActivityInfo> activityInfoList = CommonActivityMgr.getAllInTimeCommonActivityInfoList();
        if (null == activityInfoList || activityInfoList.size() <= 0) {
            useResult.setRet(GameErrorCode.E_COMMON_ACTIVITY_NO_IN_TIME);
            return useResult;
        }

        // 判断是否是活动道具
        boolean isInTimeActivityGoods = false;
        int activityId = 0;
        int scoreGoodsId = 0;
        int activityType = 0;
        for(ActivityInfo activityInfo : activityInfoList){
            if(activityInfo.getCommonActivityItemList().contains(goodsInfo.getGoodsId())){
                isInTimeActivityGoods = true;
                activityId = activityInfo.getActivityId();
                scoreGoodsId = Integer.parseInt(activityInfo.getParam2());
                activityType = activityInfo.getChildType();
                break;
            }
        }
        if(!isInTimeActivityGoods){
            useResult.setRet(GameErrorCode.E_COMMON_ACTIVITY_NO_ACTIVITY_GOODS);
            return useResult;
        }

        // 扣除道具
        BagModule bagModule = player.getModule(BagModule.class);
        long oldValue = bagModule.getUserBagItemCount(goodsInfo.getGoodsId());
        long nowValue;
        if(!player.getModule(CurrencyModule.class).removeCurrency(new Property(goodsInfo.getGoodsId(), BigInteger.valueOf(count)),
                eLogMoneyType.Activity, eLogMoneyType.CommonActivityUseGoods)){
            useResult.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return useResult;
        }
        nowValue = bagModule.getUserBagItemCount(goodsInfo.getGoodsId());
        // 获得奖励
        Property reward = new Property();
        for (int i = 0; i < count; i++) {
            OpenGoodsBagResult result = GoodsBagMgr.getRandomGoods(goodsInfo.getGoodsId());
            for(Map.Entry<Integer, BigInteger> dataEntry : result.getReward().getGoods().entrySet()){
                if(dataEntry.getKey() == scoreGoodsId){
                    BigDecimal value = new BigDecimal(dataEntry.getValue());
                    //美名对万能活动积分加成
                    double skillAddition = player.getModule(BeautyModule.class).getIdentitySkillAddition(eSkillType.CommonActivityScoreAddition.getValue(), activityType);
                    value = value.multiply(BigDecimal.valueOf(1 + skillAddition / 1000)).setScale(0, BigDecimal.ROUND_UP);
                    result.getReward().setGood(dataEntry.getKey(), value.toBigInteger());
                    break;
                }
            }
            reward.addProperty(result.getReward());
            if(result.getNotice() == 1){
                WorldMessageMgr.worldNotify(player, eMessageType.OpenGoodsBagNotice.getValue(), player.getUserInfo().getCity(), player.getTitleId(),
                        player.getUserInfo().getNickName(), goodsInfo.getGoodsId(), PropertyHelper.parsePropertyToString(result.getReward()));
            }
        }
        int specialNum = 0;
        String extendParam = goodsInfo.getExtendParam();
        String[] split = extendParam.split("\\|");
        for (String s : split) {
            String[] strings = s.split(";");
            int itemId = Integer.parseInt(strings[0]);
            if (reward.getCountByGoodsId(itemId).compareTo(BigInteger.ZERO) > 0) {
                if (strings.length >1) {
                    int tempNum = Integer.parseInt(strings[1]);
                    if (tempNum == 1) {
                        specialNum = 1;
                        break;
                    }
                    if (specialNum < tempNum) {
                        specialNum = tempNum;
                    }
                }else {
                    specialNum = 1;
                    break;
                }
            }
        }
        useResult.setSpecialReward(specialNum);
        player.getModule(CurrencyModule.class).addCurrency(reward, eLogMoneyType.Activity, eLogMoneyType.CommonActivityUseGoodsReward);
        String rewardStr = PropertyHelper.parsePropertyToString(reward);
        useResult.setReward(rewardStr);
        LogMgr.addLogCommonActivityUseGoods(player.getUserId(), activityId, goodsInfo.getGoodsId(), count, oldValue, nowValue, rewardStr);
        return useResult;
    }

    public UseGoodsResult useTrystGoods(GoodsInfo goodsInfo) {
        UseGoodsResult useResult = new UseGoodsResult();
        List<ActivityInfo> activityInfoList = NormalActivityMgr.getTrystActivityInfoList();
        if (null == activityInfoList || activityInfoList.size() <= 0) {
            useResult.setRet(GameErrorCode.E_TRYST_ACTIVITY_NO_IN_RUNNING_TIME);
            return useResult;
        }
        boolean isInTimeActivityGoods = false;
        int activityId = 0;
        for(ActivityInfo activityInfo : activityInfoList){
            int goodsId = Integer.valueOf(StringUtils.stringToStringList(activityInfo.getParam4(), ";").get(0));
            if(goodsId == goodsInfo.getGoodsId()){
                isInTimeActivityGoods = true;
                activityId = activityInfo.getActivityId();
                break;
            }
        }
        if(!isInTimeActivityGoods){
            useResult.setRet(GameErrorCode.E_TRYST_ACTIVITY_ERROR_GOODS);
            return useResult;
        }

        BagModule bagModule = player.getModule(BagModule.class);
        long oldValue = bagModule.getUserBagItemCount(goodsInfo.getGoodsId());
        long nowValue;
        BigInteger count = goodsInfo.getParamList().get(0);
        BigInteger add = goodsInfo.getParamList().get(1);
        if(!player.getModule(CurrencyModule.class).removeCurrency(new Property(goodsInfo.getGoodsId(), count),
                eLogMoneyType.Activity, eLogMoneyType.TrystActivityUseGoods)){
            useResult.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return useResult;
        }
        nowValue = bagModule.getUserBagItemCount(goodsInfo.getGoodsId());
        player.notifyListener(eGamePlayerEventType.TrystValueRise.getValue(),add);
        useResult.setReward("");
        LogMgr.addLogTrystActivityUseGoods(player.getUserId(), activityId, goodsInfo.getGoodsId(), count.intValue(), oldValue, nowValue,add.toString());
        return useResult;
    }

    public UseGoodsResult useXiaoyuCostumeActivityGoods(GoodsInfo goodsInfo) {
        UseGoodsResult useResult = new UseGoodsResult();
        List<ActivityInfo> activityInfoList = NormalActivityMgr.getXiaoyuCostumeActivityInfoList();
        if (null == activityInfoList || activityInfoList.size() <= 0) {
            useResult.setRet(GameErrorCode.E_XIAOYU_COSTUME_ACTIVITY_NO_IN_RUNNING_TIME);
            return useResult;
        }
        boolean isInTimeActivityGoods = false;
        int activityId = 0;
        for (ActivityInfo activityInfo : activityInfoList) {
            int goodsId = Integer.valueOf(StringUtils.stringToStringList(activityInfo.getParam4(), ";").get(0));
            if (goodsId == goodsInfo.getGoodsId()) {
                isInTimeActivityGoods = true;
                activityId = activityInfo.getActivityId();
                break;
            }
        }
        if(!isInTimeActivityGoods) {
            useResult.setRet(GameErrorCode.E_XIAOYU_COSTUME_ACTIVITY_ERROR_GOODS);
            return useResult;
        }

        Integer activityScoreId = null;
         Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(activityId);
        if (activityConfigMap != null && activityConfigMap.containsKey("EXCHANGE_SCORE_ITEM_ID")) {
            activityScoreId = activityConfigMap.get("EXCHANGE_SCORE_ITEM_ID").getIntValue();
        }

        BagModule bagModule = player.getModule(BagModule.class);
        long oldValue = bagModule.getUserBagItemCount(goodsInfo.getGoodsId());
        long nowValue;
        BigInteger count = goodsInfo.getParamList().get(0);
        BigInteger add = goodsInfo.getParamList().get(1);
        if(!player.getModule(CurrencyModule.class).removeCurrency(new Property(goodsInfo.getGoodsId(), count),
                eLogMoneyType.Activity, eLogMoneyType.XiaoyuCostumeActivityUseGoodsCost)) {
            useResult.setRet(GameErrorCode.E_BAG_ITEM_NO_ENOUGH);
            return useResult;
        }
        nowValue = bagModule.getUserBagItemCount(goodsInfo.getGoodsId());
        player.notifyListener(eGamePlayerEventType.XiaoyuCostumeActivityProgressValue.getValue(), new XiaoyuCostumeActivityArgs(add.longValue(), activityId));
        //积分奖励
        if (activityScoreId != null) {
            Property scoreReward = new Property(activityScoreId, goodsInfo.getParamList().get(3).multiply(count));
            player.getModule(CurrencyModule.class).addCurrency(scoreReward, eLogMoneyType.Activity, eLogMoneyType.XiaoyuCostumeActivityUseGoodsGet);
            useResult.setReward(PropertyHelper.parsePropertyToString(scoreReward));
        }
        LogMgr.addLogTrystActivityUseGoods(player.getUserId(), activityId, goodsInfo.getGoodsId(), count.intValue(), oldValue, nowValue,add.toString());
        return useResult;
    }

    /**
     * 是否限购
     */
    public boolean isLimitBuy(MallInfo mallInfo, int count) {
        if(MallMgr.isLimitBuyGoods(player, mallInfo)){
            return true;
        }
        return isOverLimitBuyCount(mallInfo, count);
    }

    /**
     * 老玩家回归商店参数特殊处理
     */
    private boolean isOldReturnSpecialMall(MallInfo mallInfo) {
        if (mallInfo.getShopType() != eShopType.OldPlayerReturnPlayerMall.getValue()) {
            return false;
        }
        if (OldPlayerReturnMgr.getNowActivityType() != OldPlayerReturnActivityType.NEW_ACTIVITY.getValue()){
            return false;
        }
        List<String> stringList = StringUtils.stringToStringList(mallInfo.getExtendParam(), "\\|");
        if (stringList.size() != 2) {
            return false;
        }
        if (player.getModule(OldPlayerReturnModule.class).getOldPlayerReturnShopLimit(mallInfo.getMallId())==null){
            return false;
        }
        return true;
    }

    /**
     * 限购
     */
    public boolean isSpecialLimitBuy(MallInfo mallInfo, int count) {
        if (mallInfo.getShopType() == eShopType.OldPlayerReturnPlayerMall.getValue()) {
            OldPlayerReturnModule oldPlayerReturnModule = player.getModule(OldPlayerReturnModule.class);
            if (!oldPlayerReturnModule.checkUserIsReturn()) {
                return true;
            }
            OldPlayerReturnShopLimit shopLimit = oldPlayerReturnModule.getOldPlayerReturnShopLimit(mallInfo.getMallId());
            if (shopLimit == null) {
                return true;
            }
            return (shopLimit.getHasBuyTimes() + count) > shopLimit.getTotalAddLimit();
        }
        return false;
    }



    /**
     * 积分限购
     * @param mallInfo
     * @return
     */
    private boolean isScoreLimitBuy(MallInfo mallInfo, int count) {
        try {
            String buyLimitParam = mallInfo.getBuyLimitParam();
            if (!buyLimitParam.equals("0")) {
                String[] split = buyLimitParam.split(";");
                //2023-11-30 限购类型，1：今日积分达到，2：累计积分达到，3：今日阶段性达到，4：累计阶段性达到
                int type = Integer.parseInt(split[0]);
                String limitScore = split[1];
                String[] priceSplit = mallInfo.getPrice().split("=");
                UserActivityScore userActivityScore = getUserActivityScore(mallInfo.getActivityId(), Integer.parseInt(priceSplit[0]));
                if (Objects.equals(limitScore, "0")) {
                    return false;
                }
                if (userActivityScore == null) {
                    int scoreItemId = ActivityMgr.getMallExchangeScoreItemId(mallInfo.getActivityId());
                    if(scoreItemId != 0){
                        userActivityScore = getUserActivityScore(mallInfo.getActivityId(), scoreItemId);
                        if (userActivityScore == null) {
                            return true;
                        }
                    }else {
                        //不是活动扩展的，走原来逻辑
                        if(type != 5) {
                            return true;
                        }
                    }
                }
                //限购判断
                return this.checkBuyLimit(mallInfo.getMallId(), type, limitScore, userActivityScore == null ? 0 : userActivityScore.getDayScore(), userActivityScore == null ? 0 : userActivityScore.getTotalScore(), count, mallInfo.getActivityId());
            }
        } catch (Exception ex) {
            MallActivityMgr.getLogger().error(ex.getMessage(), ex);
            return true;
        }
        return false;
    }

    /**
     * 限购判断
     * @param mallId
     * @param type
     * @param param
     * @param dayScore
     * @param totalScore
     * @return
     */
    private boolean checkBuyLimit(int mallId, int type, String param, long dayScore, long totalScore, int count, int activityId) {
        if (type == eMallBuyLimitType.DAILY_LIMIT.getIntValue()) {
            //每日积分限购
            int checkScore = Integer.parseInt(param);
            if (dayScore < checkScore) {
                return true;
            }
        }
        if (type == eMallBuyLimitType.ACTION_LIMIT.getIntValue()) {
            //活动期间内积分限购
            int checkScore = Integer.parseInt(param);
            if (totalScore < checkScore) {
                return true;
            }
        }
        if (type == eMallBuyLimitType.DAILY_STAGE_LIMIT.getIntValue() || type == eMallBuyLimitType.ACTION_STAGE_LIMIT.getIntValue()) {
            //今日阶段性||活动期间内阶段性
            long checkScore = dayScore;
            if (type == eMallBuyLimitType.ACTION_STAGE_LIMIT.getIntValue()) {
                checkScore = totalScore;
            }
            String[] paramStrArr = param.split("\\|");
            //计算出，可购买的次数
            int allCanBuyTime = 0;
            for (String paramStr : paramStrArr) {
                String[] stageParamArr = paramStr.split(",");
                int score = Integer.parseInt(stageParamArr[0]);
                int canBuyTime = Integer.parseInt(stageParamArr[1]);
                if (checkScore >= score) {
                    allCanBuyTime += canBuyTime;
                }
            }
            //获取购买过的次数
            int buyTime = this.getMallBuyCount(mallId);
            //剩余可买的次数
            int reBuyTime = allCanBuyTime - buyTime;
            if (count > reBuyTime) {
                return true;
            }
        }
        if (type == eMallBuyLimitType.ACTIVITY_EXTEND.getIntValue() && activityId > 0){
            ActivityInfo openActivityInfo = ActivityMgr.getOpenActivityInfo(activityId);
            if(openActivityInfo != null){
                IActivityMallLimitHandler handler = ActivityMgr.getIActivityMallLimitHandler(openActivityInfo.getType());
                if(handler != null){
                    return handler.isBuyLimit(player, mallId, activityId, param, count);
                }
            }
        }
        return false;
    }

    /**
     * 是否超过可购数量
     */
    public boolean isOverLimitBuyCount(MallInfo mallInfo, int count) {
        if(-1 == mallInfo.getLimitBuyCount()){
            return false;
        }
        int currentCount = 0;
        // 无双美女抽奖特殊处理，多个商品共用一个限购
        if (mallInfo.getShopType() == eShopType.PeerlessBeautyLotteryMall.getValue() && !"0".equals(mallInfo.getExtendParam())) {
            MallActivityInfo mallActivityInfo = MallActivityMgr.getInTimeActivity(mallInfo.getActivityId());
            if (mallActivityInfo == null) {
                return false;
            }
            List<Integer> p1 = StringUtils.stringToIntegerList(mallInfo.getExtendParam(), ";");
            for (MallInfo data : mallActivityInfo.getMallInfoMap().values()) {
                if ("0".equals(data.getExtendParam())) {
                    continue;
                }
                List<Integer> p2 = StringUtils.stringToIntegerList(data.getExtendParam(), ";");
                if (Objects.equals(p2.get(1), p1.get(1))) {
                    // 累计数
                    if (userMallBuyCountMap.containsKey(data.getMallId())) {
                        currentCount += userMallBuyCountMap.get(data.getMallId()).getCount();
                    }
                }
            }
        } else {
            if (userMallBuyCountMap.containsKey(mallInfo.getMallId())) {
                currentCount = userMallBuyCountMap.get(mallInfo.getMallId()).getCount();
            }
        }
        return currentCount + count > mallInfo.getLimitBuyCount();
    }

    private void syncMallBuyCount(List<UserMallBuyCount> userMallBuyCountList) {
        if(hasActivity()){//有活动时同步
            player.sendPacket(Protocol.U_MALL_BUY_COUNT_SYNC, MallPb.parseMallBuyCountListMsg(userMallBuyCountList));
        }
    }

    private void syncActivityScore(List<UserActivityScore> userActivityScores) {
        syncSpecialActivityScore(userActivityScores);
        if (hasActivity()) {
            player.sendPacket(Protocol.U_ACTIVITY_SCORE_SYNC, MallPb.parseActivityScore(userActivityScores));
        }
    }

    private void syncMallBuyCount(UserMallBuyCount userMallBuyCount) {
        if (null != userMallBuyCount) {
            List<UserMallBuyCount> syncList = new ArrayList<>();
            syncList.add(userMallBuyCount);
            syncMallBuyCount(syncList);
        }
    }

    public int getMallBuyCount(int mallId) {
        if (userMallBuyCountMap.containsKey(mallId)) {
            return userMallBuyCountMap.get(mallId).getCount();
        }
        return 0;
    }

    /**
     * 获取玩家购买的礼包信息
     * @param mallId
     * @return
     */
    public UserMallBuyCount getUserMall(int mallId) {
        return userMallBuyCountMap.get(mallId);
    }

    /**
     * 增加购买数量
     */
    public void addMallBuyCount(MallInfo mallInfo, int count) {
        if (isOldReturnSpecialMall(mallInfo)){
            OldPlayerReturnModule oldPlayerReturnModule = player.getModule(OldPlayerReturnModule.class);
            OldPlayerReturnShopLimit oldPlayerReturnShopLimit = oldPlayerReturnModule.getOldPlayerReturnShopLimit(mallInfo.getMallId());
            oldPlayerReturnShopLimit.setHasBuyTimes(oldPlayerReturnShopLimit.getHasBuyTimes()+count);
            oldPlayerReturnModule.addMallLimitSync(oldPlayerReturnShopLimit);
            return;
        }
        if (mallInfo.getPriceAdd() > 0 || -1 != mallInfo.getLimitBuyCount()) {// 如果是限购的 或者是有累加金额的才添加
            UserMallBuyCount mallBuyCount = userMallBuyCountMap.get(mallInfo.getMallId());
            if (null == mallBuyCount) {
                mallBuyCount = new UserMallBuyCount();
                mallBuyCount.setMallId(mallInfo.getMallId());
                mallBuyCount.setUserId(player.getUserId());
                mallBuyCount.setActivityId(mallInfo.getActivityId());
                mallBuyCount.setInsertOption();
                userMallBuyCountMap.put(mallBuyCount.getMallId(), mallBuyCount);
            }
            mallBuyCount.setCount(mallBuyCount.getCount() + count);
            mallBuyCount.setLastUpdateTime(System.currentTimeMillis() / 1000);
            syncMallBuyCount(mallBuyCount);
        }
    }


    /**
     * 获得分数
     * @param activityId
     * @param score
     */
    public void addScore(int activityId, int goodsId, long score) {
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        if (activityInfo == null) {
            activityInfo = CommonActivityMgr.getOpenCommonActivityInfo(activityId);
        }
        if (activityInfo == null) {
            activityInfo = TradeWarActivityMgr.getOpenActivityInfo(activityId);
        }
        if (activityInfo == null) {
            activityInfo = OreWarActivityMgr.getOpenActivityInfo(activityId);
        }
        if (activityInfo == null) {
            activityInfo = StrongholdActivityMgr.getOpenActivityInfo(activityId);
        }
        if (activityInfo == null) {
            activityInfo = UnionWarActivityMgr.getOpenActivityInfo(activityId);
        }
        if (activityInfo == null) {
            activityInfo = RelationActivityMgr.getOpenActivityInfo(activityId);
        }
        if (activityInfo == null) {
            return;
        }
        if (!userActivityScoreMap.containsKey(activityId)) {
            userActivityScoreMap.put(activityId, new ConcurrentHashMap<>());
        }
        if (!userActivityScoreMap.get(activityId).containsKey(goodsId)) {
            UserActivityScore userActivityScore = new UserActivityScore();
            userActivityScore.setActivityId(activityId);
            userActivityScore.setActivityType(activityInfo.getType());
            userActivityScore.setUserId(getUserId());
            userActivityScore.setGoodsId(goodsId);
            userActivityScore.setDayScore(0L);
            userActivityScore.setTotalScore(0L);
            userActivityScore.setLastResetTime(System.currentTimeMillis());
            userActivityScore.setInsertOption();
            userActivityScoreMap.get(activityId).put(goodsId, userActivityScore);
        }
        UserActivityScore userActivityScore = userActivityScoreMap.get(activityId).get(goodsId);
        activityScoreResetOneDay(userActivityScore);
        userActivityScore.setDayScore(userActivityScore.getDayScore() + score);
        userActivityScore.setTotalScore(userActivityScore.getTotalScore() + score);
        List<UserActivityScore> userActivityScores = new ArrayList<>();
        userActivityScores.add(userActivityScore);
        syncActivityScore(userActivityScores);
    }

    /**
     * 活动每日积分重置
     * @param userActivityScore
     */
    public void activityScoreResetOneDay(UserActivityScore userActivityScore) {
        long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp();
        if (userActivityScore.getLastResetTime() < zeroTime) {
            userActivityScore.setDayScore(0L);
            userActivityScore.setLastResetTime(System.currentTimeMillis());
        }
    }

    public void activityScoreResetOneDay() {
        if (userActivityScoreMap != null) {
            for (Map<Integer, UserActivityScore> map : userActivityScoreMap.values()) {
                for (UserActivityScore score : map.values()) {
                    activityScoreResetOneDay(score);
                }
            }
            syncActivityScore();
        }
    }

    public UserActivityScore getUserActivityScore(int activityId, int goodsId) {
        if (!userActivityScoreMap.containsKey(activityId)) {
            return null;
        }
        return userActivityScoreMap.get(activityId).get(goodsId);
    }

    public Map<Integer, Map<Integer, UserActivityScore>> getUserActivityScoreMap() {
        return userActivityScoreMap;
    }

    /**
    * 描述：获取当前可以购买数量
    * 作者：zrq
    * 时间：2023/2/11
    * 参数：

    * 返回值：
    **/
    public int getLimitCount(MallInfo mallInfo) {
        if(null == mallInfo){
            return 0;
        }
        if(-1 == mallInfo.getLimitBuyCount()){
            return Integer.MAX_VALUE;
        }
        int currentCount = 0;
        if (userMallBuyCountMap.containsKey(mallInfo.getMallId())) {
            currentCount = userMallBuyCountMap.get(mallInfo.getMallId()).getCount();
        }
        int limitCount = mallInfo.getLimitBuyCount() - currentCount;
        if(limitCount < 0){
            limitCount = 0;
        }
        return limitCount;
    }

    /**
     * 校验线性礼包活动，当前礼包前的礼包是否解锁并购买
     *
     * @param mallInfo 商品信息
     * @return retCode
     */
    public int checkLinearPackLocked(MallInfo mallInfo) {
        if (mallInfo == null) {
            return GameErrorCode.E_MALL_CONFIG_ERROR;
        }

        int activityId = mallInfo.getActivityId();
        String[] extendParam = mallInfo.getExtendParam().split("\\|"); // 1|0 礼包分类|类型
        int type = Integer.parseInt(extendParam[0]); // 礼包分类

        // 获取活动礼包配置
        Map<Integer, Map<Integer, MallInfo>> allActivityMallInfoMap = ActivityMgr.getAllActivityMallInfoMap();
        Map<Integer, MallInfo> mallInfoMap = allActivityMallInfoMap.get(activityId);
        if (mallInfoMap == null) {
            return GameErrorCode.E_MALL_CONFIG_ERROR;
        }

        List<Integer> buyList = new ArrayList<>(); // 已购的同类礼包顺序
        for (UserMallBuyCount buyCount : userMallBuyCountMap.values()) {
            if (buyCount.getActivityId() == activityId && buyCount.getCount() >= 1) { // 已经购买过的礼包加入校验
                for (MallInfo mall : mallInfoMap.values()) {
                    String[] extendParam1 = mall.getExtendParam().split("\\|");
                    int type1 = Integer.parseInt(extendParam1[0]);
                    if (type == type1 && mall.getMallId() == buyCount.getMallId()) { // 同一分页的礼包
                        buyList.add(mall.getSort());
                    }
                }
            }
        }

        Collections.sort(buyList);
        int sort = mallInfo.getSort();
        int idx;
        for (idx = 1; idx < sort; idx++) { // 判断当前礼包前的礼包是否都有购买
            if (!buyList.contains(idx)) {
                return GameErrorCode.E_MALL_CONFIG_ERROR;
            }
        }

        // 当前商品是重复购买或者是最新已购买的下一个
        return (buyList.contains(sort) || idx == sort) ? 0 : GameErrorCode.E_MALL_CONFIG_ERROR;
    }
}
